//
// Created by pedro on 18-10-20.
//


#include "quick_sort.h"

int partition(int *data, int p, int r) {
    int x = data[r];
    int i = p - 1;
    for (int j = p; j <= r - 1; ++j) {
        if (data[j] <= x) {
            i = i + 1;
            swap(data, i, j);
        }
    }
    swap(data, i + 1, r);
    return i + 1;
}

void quick_sort(int *data, int p, int r) {
    if (p < r) {
        int q = partition(data, p, r);
        quick_sort(data, p, q - 1);
        quick_sort(data, q + 1, r);
    }
}


